<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BApplicationConfig
 *
 * @author ID59C
 */
class BServiceConfig extends BConfig {

    private $paths = null;

    //put your code here
    public function init() {
        parent::init();
        $this->initPath();
        $this->initImport();
    }

    /**
     * config file under service setup global meta of service
     * specific config meta saved into database with service
     */
    public function parseConfig() {

        parent::parseConfig();

        $service = $this->parent;
        if (!$this->parent instanceof BService)
            $service = Blyn::app()->getActiveService();

        if (isset($service->data['config'])) {
            $this->config = array_merge($this->config, $service->data['config']);
        }
    }

    protected function initPath() {

        $basePath = 'application.application.service';

        $paths = $this->paths = array(
            'basePath' => $basePath,
            //        'authPath' => $basePath . '.auth',
            //        'dbPath' => $basePath . '.db',
            'uiPath' => $basePath . '.ui',
            'configPath' => $basePath . '.config',
                //         'dataPath' => $basePath . '.data',
                //         'appPath' => $basePath . '.app',
        );

        foreach ($paths as $name => $value) {
            $this->parent->setComponentProperty($name, $value);
        }
    }

    public function initImport() {
        $paths = $this->paths;
        yii::import($paths['basePath'] . '.*');
        //       yii::import($paths['appPath'] . '.*');
        yii::import($paths['uiPath'] . '.*');
//        yii::import($paths['authPath'] . '.*');
//        yii::import($paths['dataPath'] . '.*');
//        yii::import($paths['dbPath'] . '.*');
    }

    public function saveConfig($config) {
        
    }

}

?>
